Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use Helia's blockBroker interface #406

Merged
merged 10 commits into from
Nov 29, 2023

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented Nov 29, 2023

  • Update Helia and libp2p dependencies
    • also updated others. basically ncu '/ipfs|libp2p|ipld|multi/'
  • Use Helia blockBroker interface for block retrieval
  • Use kubo-rpc-client as a blockBroker
    • Use Kubo as a trustless gateway
    • Remove dependency on kubo-rpc-client (and many older ipfs dependencies)
  • Remove all places where kuboClient was passed through since that is no longer needed.
  • Update hashers passed to helia so it can support parsing of multiple content types
  • Disable libp2p autoDialer because we only want to fetch on demand.

These updates also put a big dent in dependencies holding back ipfs-webui ipfs/ipfs-webui#1965

@SgtPooki SgtPooki requested a review from a team as a code owner November 29, 2023 01:10
@SgtPooki SgtPooki requested a review from lidel November 29, 2023 01:10
@SgtPooki SgtPooki changed the title feat: use Helia's blockBroker interface feat!: use Helia's blockBroker interface Nov 29, 2023
Copy link
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow 🤩

src/bundles/helia.ts Show resolved Hide resolved
src/lib/get-raw-block.ts Show resolved Hide resolved
src/lib/init-helia.ts Outdated Show resolved Hide resolved
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review and explainers

Comment on lines +94 to +97
const { doInitHelia } = props
useEffect(() => {
props.doInitHelia()
}, [props])
doInitHelia()
}, [doInitHelia])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes an issue where doInitHelia was being called on every page load.

Comment on lines +82 to +95
/**
* replace bigint or other non-JSON-serializable values with appropriate values for the react-inspector
* Note that data for some blocks (e.g. bafyreicnokmhmrnlp2wjhyk2haep4tqxiptwfrp2rrs7rzq7uk766chqvq) currently do not
* look like NormalizedDagNode['data']
*
* @param {import('../../types').NormalizedDagNode['data']} data
*/
const getObjectInspectorData = (data) => {
if (data == null) return data
if (data.blockSizes != null) {
data.blockSizes = data.blockSizes.map(Number)
}
return data
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed since the unixfs update uses bigint now.

Comment on lines +97 to 113
/**
* @param {object} props
* @param {import('react-i18next').TFunction} props.t
* @param {boolean} props.tReady
* @param {string} props.className
* @param {string} props.type
* @param {string} props.cid
* @param {string} props.localPath
* @param {bigint} props.size
* @param {import('../../types').NormalizedDagNode['data']} props.data
* @param {object[]} props.links
* @param {string} props.format
* @param {Function} props.onLinkClick
* @param {string} props.gatewayUrl
* @param {string} props.publicGatewayUrl
*/
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some types

const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
if (!tReady) return null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always true in testing, but may not always be in prod.

@@ -130,7 +162,7 @@ const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, li
<div className='dt dt--fixed pt2'>
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label className='dtc silver tracked ttu f7' style={{ width: 48 }}>Size</label>
<div className='dtc truncate charcoal monospace'>{humansize(size)}</div>
<div className='dtc truncate charcoal monospace'>{humansize(Number(size))}</div>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigint conversion

Comment on lines 10 to 13
interface CodecWrapper<DecodedType = any> {
decode: (bytes: Uint8Array) => DecodedType
resolve: (path: string, bytes: Uint8Array) => Promise<ResolveType<DecodedType>>
decode(bytes: Uint8Array): DecodedType
resolve(path: string, bytes: Uint8Array): Promise<ResolveType<DecodedType>>
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint-config-ipfs auto lint updates

const timeoutId = setTimeout(() => { abortController.abort('Request timed out') }, timeout)
const rawBlock = await Promise.any([kuboClient.block.get(cid), getBlockFromAnyGateway(cid, abortController.signal), helia.blockstore.get(cid, { signal: abortController.signal })])
abortController.abort('Content obtained') // abort any other requests.
const rawBlock = await helia.blockstore.get(cid, { signal: abortController.signal })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so much nicer =D

@@ -11,7 +11,7 @@ export interface DigestFn {
(data: Uint8Array): Promise<MultihashDigest<number>>
}

export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode: (n: T) => Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> {
export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode(n: T): Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint-config-ipfs auto lint updates

@@ -52,11 +51,18 @@ export default async function initHelia (kuboClient: ReturnType<typeof createKub
],
services: {
identify: identifyService(),
autoNAT: autoNATService()
autoNAT: autoNATService(),
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use delegated routingv1httpApi instead of local kubo

Comment on lines +5 to +22
export default defineConfig((configEnv) => mergeConfig(
viteConfig(configEnv),
defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: './test/unit/setup.js',
include: [
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
],
deps: {
inline: [
'ipld-explorer-components'
]
}
}
}
}))
})
))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearing out package-lock.json and refreshing it caused an error here.. vitest must've updated their api (they're still pre v1)

@SgtPooki SgtPooki merged commit c964a76 into master Nov 29, 2023
16 checks passed
@SgtPooki SgtPooki deleted the feat/use-blockBroker-interface branch November 29, 2023 18:54
github-actions bot pushed a commit that referenced this pull request Nov 30, 2023
## [5.0.0](v4.0.3...v5.0.0) (2023-11-30)

### ⚠ BREAKING CHANGES

* update of many ipfs/ipld/libp2p/helia deps that may break consumers. API of ipld-explorer-components has not changed.

### Features

* use Helia's blockBroker interface ([#406](#406)) ([c964a76](c964a76))
* use ipfs-css colors and add dag-jose example ([#408](#408)) ([4e96491](4e96491))

### Trivial Changes

* bump protobufjs from 6.11.3 to 6.11.4 ([#393](#393)) ([f8db274](f8db274))
* **ci:** remove circleci config ([#388](#388)) ([13698af](13698af))
* pull new translations ([#390](#390)) ([2caac4a](2caac4a))
* pull new translations ([#396](#396)) ([73799f8](73799f8))
* pull new translations ([#405](#405)) ([5805bd8](5805bd8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants